package com.cskaoyan;

import com.cskaoyan.utils.JDBCUtils;
import com.mysql.jdbc.Driver;

import java.sql.*;

/**
 * 创建日期: 2022/10/07 17:29
 *
 * @author ciggar
 */
public class UseUtilsJDBC {


    public static void main(String[] args) throws SQLException {

        // 1. 获取连接
        Connection connection = JDBCUtils.getConnection();

        // 2. 创建Statement对象
        Statement statement = connection.createStatement();

        // 3. 执行SQL语句
        ResultSet resultSet = statement.executeQuery("select * from stu");

        while (resultSet.next()) {

            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            String clazz = resultSet.getString("clazz");

            System.out.println("id:" + id + ",name:" + name + ",clazz:" +clazz);
        }

        // 4. 关闭资源
        JDBCUtils.closeResource(resultSet,statement,connection);
    }
}
